import MoldBaseUtils from "@/editor/framework/utils/MoldBaseUtils";
import Const from "@/libs/const/const";
import { Vector3 } from "three";
// TODO:加下每个面的normal 
export default class MoldUtils {

    /**
     * 墙
     * @param data 
     */
    static getWallVI(data: IWallParams) {

        // 计数
        let count: number = 0;
        // 数据
        let vertices: number[] = [];
        let indices: number[] = [];
        let facevec: any[] = [];
        let uv: number[] = [];

        // 长宽高
        let L: number = Number(data.L);
        let W: number = Number(data.W);
        let H: number = Number(data.H);

        let ldir: Vector3 = Const.vec1.set(data.ldir[0], data.ldir[1], data.ldir[2]);
        let wdir: Vector3 = Const.vec2.set(data.wdir[0], data.wdir[1], data.wdir[2]);
        let hdir: Vector3 = Const.vec3.set(data.hdir[0], data.hdir[1], data.hdir[2]);

        let s1: Vector3 = Const.origin.clone().sub(wdir.setLength(W / 2)).add(hdir.setLength(H));
        let s2: Vector3 = s1.clone().add(ldir.setLength(L));
        let s3: Vector3 = s2.clone().add(wdir.setLength(W));
        let s4: Vector3 = s3.clone().sub(ldir.setLength(L));

        let b1: Vector3 = Const.origin.clone().sub(wdir.setLength(W / 2));
        let b2: Vector3 = b1.clone().add(ldir.setLength(L));
        let b3: Vector3 = b2.clone().add(wdir.setLength(W));
        let b4: Vector3 = b3.clone().sub(ldir.setLength(L));

        let topface: Vector3[] = [s1, s2, s3, s4, s1];
        let bottomface: Vector3[] = [b1, b2, b3, b4, b1];

        let side = MoldBaseUtils.getVIF(bottomface, topface, count);
        vertices.push(...side[0]);
        indices.push(...side[1]);
        uv.push(...side[2]);
        facevec.push(...side[3]);
        count = side[4];

        return [vertices, indices, uv, facevec];
    }


    /**
     * 梁
     * @param data 
     */
    static getBeamVI(data: IWallParams) {

        // 计数
        let count: number = 0;
        // 数据
        let vertices: number[] = [];
        let indices: number[] = [];
        let facevec: any[] = [];
        let uv: number[] = [];

        // 长宽高
        let L: number = Number(data.L);
        let W: number = Number(data.W);
        let H: number = Number(data.H);

        let ldir: Vector3 = Const.vec1.set(data.ldir[0], data.ldir[1], data.ldir[2]);
        let wdir: Vector3 = Const.vec2.set(data.wdir[0], data.wdir[1], data.wdir[2]);
        let hdir: Vector3 = Const.vec3.set(data.hdir[0], data.hdir[1], data.hdir[2]);

        let s1: Vector3 = Const.origin.clone().sub(wdir.setLength(W / 2));
        let s2: Vector3 = s1.clone().add(ldir.setLength(L));
        let s3: Vector3 = s2.clone().add(wdir.setLength(W));
        let s4: Vector3 = s3.clone().sub(ldir.setLength(L));

        let b1: Vector3 = Const.origin.clone().sub(wdir.setLength(W / 2)).add(hdir.setLength(H));
        let b2: Vector3 = b1.clone().add(ldir.setLength(L));
        let b3: Vector3 = b2.clone().add(wdir.setLength(W));
        let b4: Vector3 = b3.clone().sub(ldir.setLength(L));

        let topface: Vector3[] = [s1, s2, s3, s4, s1];
        let bottomface: Vector3[] = [b1, b2, b3, b4, b1];

        let side = MoldBaseUtils.getVIF(bottomface, topface, count);
        vertices.push(...side[0]);
        indices.push(...side[1]);
        uv.push(...side[2]);
        facevec.push(...side[3]);
        count = side[4];

        return [vertices, indices, uv, facevec];
    }

     /**
     * 梁
     * @param data 
     */
      static getPillarVI(data: IWallParams) {

        // 计数
        let count: number = 0;
        // 数据
        let vertices: number[] = [];
        let indices: number[] = [];
        let facevec: any[] = [];
        let uv: number[] = [];

        // 长宽高
        let L: number = Number(data.L);
        let W: number = Number(data.W);
        let H: number = Number(data.H);

        let ldir: Vector3 = Const.vec1.set(data.ldir[0], data.ldir[1], data.ldir[2]);
        let wdir: Vector3 = Const.vec2.set(data.wdir[0], data.wdir[1], data.wdir[2]);
        let hdir: Vector3 = Const.vec3.set(data.hdir[0], data.hdir[1], data.hdir[2]);

        let s1: Vector3 = Const.origin.clone().add(hdir.setLength(H)).sub(wdir.setLength(W / 2)).sub(ldir.setLength(L/2));
        let s2: Vector3 = s1.clone().add(ldir.setLength(L));
        let s3: Vector3 = s2.clone().add(wdir.setLength(W));
        let s4: Vector3 = s3.clone().sub(ldir.setLength(L));

        let b1: Vector3 = Const.origin.clone().sub(wdir.setLength(W / 2)).sub(ldir.setLength(L/2));
        let b2: Vector3 = b1.clone().add(ldir.setLength(L));
        let b3: Vector3 = b2.clone().add(wdir.setLength(W));
        let b4: Vector3 = b3.clone().sub(ldir.setLength(L));

        let topface: Vector3[] = [s1, s2, s3, s4, s1];
        let bottomface: Vector3[] = [b1, b2, b3, b4, b1];

        let side = MoldBaseUtils.getVIF(bottomface, topface, count);
        vertices.push(...side[0]);
        indices.push(...side[1]);
        uv.push(...side[2]);
        facevec.push(...side[3]);
        count = side[4];

        return [vertices, indices, uv, facevec];
    }


     /**
     * 梁
     * @param data 
     */
      static getFloorVI(data: IWallParams) {

        // 计数
        let count: number = 0;
        // 数据
        let vertices: number[] = [];
        let indices: number[] = [];
        let facevec: any[] = [];
        let uv: number[] = [];

        // 长宽高
        let L: number = Number(data.L);
        let W: number = Number(data.W);
        let H: number = Number(data.H);

        let ldir: Vector3 = Const.vec1.set(data.ldir[0], data.ldir[1], data.ldir[2]);
        let wdir: Vector3 = Const.vec2.set(data.wdir[0], data.wdir[1], data.wdir[2]);
        let hdir: Vector3 = Const.vec3.set(data.hdir[0], data.hdir[1], data.hdir[2]);

        let s1: Vector3 = Const.origin.clone().sub(wdir.setLength(W / 2)).sub(ldir.setLength(L/2));
        let s2: Vector3 = s1.clone().add(wdir.setLength(W));
        let s3: Vector3 = s2.clone().add(ldir.setLength(L));
        let s4: Vector3 = s3.clone().sub(wdir.setLength(W));

        let b1: Vector3 = Const.origin.clone().add(hdir.setLength(H)).sub(wdir.setLength(W / 2)).sub(ldir.setLength(L/2));
        let b2: Vector3 = b1.clone().add(wdir.setLength(W));
        let b3: Vector3 = b2.clone().add(ldir.setLength(L));
        let b4: Vector3 = b3.clone().sub(wdir.setLength(W));

        let topface: Vector3[] = [s1, s2, s3, s4, s1];
        let bottomface: Vector3[] = [b1, b2, b3, b4, b1];

        let side = MoldBaseUtils.getVIF(bottomface, topface, count);
        vertices.push(...side[0]);
        indices.push(...side[1]);
        uv.push(...side[2]);
        facevec.push(...side[3]);
        count = side[4];

        return [vertices, indices, uv, facevec];
    }
}